<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="门店" prop="storeId">
                <el-select v-model="queryParams.storeId" placeholder="请选择" filterable>
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="timebox">
                <el-form-item label="Mac状态" prop="macStatus">
                  <el-select
                    v-model="queryParams.macStatus"
                    placeholder="请选择"
                    class="w-300"
                  >
                    <el-option
                      v-for="item in macStatusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="timebox">
                <el-form-item label="Mac备注" prop="macDesc">
                  <el-input
                    v-model="queryParams.macDesc"
                    placeholder="请输入备注"
                    class="w-300"
                  ></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <div class="timebox">
                <el-form-item label="日期时间" prop="date">
                  <timer
                    ref="timer"
                    :timer.sync="queryParams.date"
                    @query="handleQuery"
                    :isCheck="false"
                  ></timer>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <!-- 门店Mac列表 -->
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">门店Mac列表</div>
      </div>

      <div class="table_list">
        <el-table
          :data="StoresList"
          stripe
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="createTime" label="创建时间">
          </el-table-column>
          <el-table-column prop="macCode" label="MAC编码"> </el-table-column>
          <el-table-column prop="macDesc" label="MAC申请备注">
          </el-table-column>
          <el-table-column prop="macStatusStr" label="MAC状态">
          </el-table-column>

          <el-table-column prop="macType" label="类型">
            <template slot-scope="scope">
              {{ macTypeOptions[scope.row.macType] }}
            </template>
          </el-table-column>
          <el-table-column prop="objectName" label="申请名称">
          </el-table-column>
          <el-table-column prop="date" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="ApprovalBtn(scope.row)"
                v-if="scope.row.macStatus === 'W'"
                >审批</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="Disable(scope.row, 0)"
                v-if="
                  scope.row.macStatus === 'W' || scope.row.macStatus === 'F'
                "
                >禁用</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="Disable(scope.row, 1)"
                v-if="scope.row.macStatus === 'C'"
                >取消禁用</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
  
  <script>
import timer from "@/components/getTime/timer";
import {
  getStoreMacPage,
  ApproveMacBtn,
  CancelMacBtn,
} from "@/api/bpm/maclimit";

import UpFiles from "@/components/UpFiles";
export default {
  name: "EryuoaStorepersonList",
  components: { UpFiles, timer },
  data() {
    return {
      AddStoreUser: false,
      AddStoreUserTitle: "",

      value: true,
      value1: "",
      loading: false,
      StoresList: [], // 列表数据

      options: [],

      // 状态
      macTypeOptions: {
        S: "门店",
        U: "用户",
      },
      macStatusOptions: [
        {
          value: "W",
          label: "待审批",
        },
        {
          value: "F",
          label: "已审批",
        },
        {
          value: "C",
          label: "取消",
        },
      ],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        startTime: "",
        endTime: "",
        macDesc:"",
        macStatus:"",
        date: [],
      },
      total: 0,
    };
  },

  created() {
    this.getList();
  },

  mounted() {},

  methods: {
    ApprovalBtn(row) {
      this.$confirm("确认进行审批操作吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          ApproveMacBtn({ macId: row.macId })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.getList();
                this.$message({
                  type: "success",
                  message: "操作成功!",
                });
              }
            })
            .catch((err) => {});
        })
        .catch(() => {});
    },

    // 禁用
    Disable(row, status) {
      let title =
        "确认" +
        (status === 0 ? "禁用" : status === 1 ? "取消禁用" : "") +
        "吗?";
      this.$confirm(title, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          CancelMacBtn({ macId: row.macId })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.getList();
                this.$message({
                  type: "success",
                  message: "操作成功!",
                });
              }
            })
            .catch((err) => {});
        })
        .catch(() => {});
    },

    CancleApprovalBtn() {
      this.$confirm("确认取消操作吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          CancelMacBtn({ macId: row.macId })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.getList();
                this.$message({
                  type: "success",
                  message: "操作成功!",
                });
              }
            })
            .catch((err) => {});
        })
        .catch(() => {});
    },

    TextPassword(rule, value, callback) {
      if (!this.AddStoreUserForm.id && !value) {
        callback(new Error("错误"));
      } else {
        callback();
      }
    },

    AddStoreUserClose() {
      this.resetFormData("AddStoreUserForm");
      this.$nextTick(() => {
        this.AddStoreUser = false;
        this.AddStoreUserForm.passWord = "";
        this.AddStoreUserForm.id = "";
        this.AddStoreUserForm.roleLabel = "";
      });
    },

    approvalCancle() {
      this.resetFormData("approvalForm");
      this.$nextTick(() => {
        this.approvalVis = false;
        this.approvalLoading = false;
      });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    getList() {
      this.loading = true;

      let query = JSON.parse(JSON.stringify(this.queryParams));
      if (!!query.date) {
        query.startTime = this.queryParams.date[0];
        query.endTime = this.queryParams.date[1];
      }

      delete query.date;

      getStoreMacPage(query)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.StoresList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      this.$refs[formName].resetFields();
    },

    publishGood() {},

    rest() {
      //   this.queryParams.deptId = undefined;
      //   this.queryParams.mobile = "";
    },

    // handleClose(done) {
    //   this.$confirm("确认关闭？")
    //     .then((_) => {
    //       done();
    //     })
    //     .catch((_) => {});
    // },
  },
};
</script>
  
  <style lang="scss" scoped>
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}
.approvalItem {
  padding: 10px 24px;
}
.pwd {
  text-security: disc;
  -webkit-text-security: disc;
}
</style>
  